package com.example.enrollservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.enrollservice.entity.enrollment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface enrollmentMapper extends BaseMapper<enrollment> {
    
    @Select("SELECT e.*, c.title as course_title, c.description as course_description " +
            "FROM enrollment e " +
            "LEFT JOIN course c ON e.course_id = c.id " +
            "WHERE e.user_id = #{userId} AND e.status = 1")
    List<Map<String, Object>> getStudentEnrollments(@Param("userId") int userId);
    
    @Select("SELECT e.*, u.username, u.email " +
            "FROM enrollment e " +
            "LEFT JOIN user_account u ON e.user_id = u.id " +
            "WHERE e.course_id = #{courseId}")
    List<Map<String, Object>> getCourseEnrollments(@Param("courseId") int courseId);
    
    @Select("SELECT * FROM enrollment WHERE user_id = #{userId} AND course_id = #{courseId}")
    enrollment getEnrollmentByUserAndCourse(@Param("userId") int userId, @Param("courseId") int courseId);
}
